VERSION 5.00
Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"
Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0"; "MSDATGRD.OCX"
Object = "{F0D2F211-CCB0-11D0-A316-00AA00688B10}#1.0#0"; "MSDATLST.OCX"
Begin VB.Form frmINV540 
   BackColor       =   &H00800000&
   Caption         =   "INV540"
   ClientHeight    =   6975
   ClientLeft      =   435
   ClientTop       =   1035
   ClientWidth     =   11040
   ControlBox      =   0   'False
   LinkTopic       =   "Form1"
   ScaleHeight     =   6975
   ScaleWidth      =   11040
   Begin MSAdodcLib.Adodc Adodc2 
      Height          =   330
      Left            =   7695
      Top             =   615
      Visible         =   0   'False
      Width           =   1800
      _ExtentX        =   3175
      _ExtentY        =   582
      ConnectMode     =   0
      CursorLocation  =   3
      IsolationLevel  =   -1
      ConnectionTimeout=   15
      CommandTimeout  =   30
      CursorType      =   3
      LockType        =   3
      CommandType     =   8
      CursorOptions   =   0
      CacheSize       =   50
      MaxRecords      =   0
      BOFAction       =   0
      EOFAction       =   0
      ConnectStringType=   1
      Appearance      =   1
      BackColor       =   -2147483643
      ForeColor       =   -2147483640
      Orientation     =   0
      Enabled         =   -1
      Connect         =   ""
      OLEDBString     =   ""
      OLEDBFile       =   ""
      DataSourceName  =   ""
      OtherAttributes =   ""
      UserName        =   ""
      Password        =   ""
      RecordSource    =   ""
      Caption         =   "2.IIM"
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      _Version        =   393216
   End
   Begin VB.CommandButton cmdPrint 
      Caption         =   "&Print"
      Height          =   456
      Left            =   4590
      TabIndex        =   24
      Top             =   6480
      Width           =   1128
   End
   Begin VB.CommandButton cmdAddNew 
      Caption         =   "New &Tag"
      Height          =   456
      Left            =   1245
      TabIndex        =   23
      Top             =   6480
      Width           =   1200
   End
   Begin VB.CommandButton cmdSave 
      Caption         =   "&Save"
      Height          =   456
      Left            =   2445
      TabIndex        =   22
      Top             =   6480
      Width           =   1080
   End
   Begin VB.CommandButton cmdCancel 
      Caption         =   "&Cancel"
      Height          =   456
      Left            =   3510
      TabIndex        =   21
      Top             =   6480
      Width           =   1080
   End
   Begin VB.CommandButton cmdExit 
      Caption         =   "&Exit"
      Height          =   456
      Left            =   5745
      TabIndex        =   20
      Top             =   6480
      Width           =   1044
   End
   Begin VB.CommandButton cmdReview 
      Caption         =   "&Review Tag"
      Height          =   432
      Left            =   135
      TabIndex        =   19
      Top             =   6495
      Width           =   1092
   End
   Begin MSAdodcLib.Adodc Adodc1 
      Height          =   330
      Left            =   7215
      Top             =   165
      Visible         =   0   'False
      Width           =   1950
      _ExtentX        =   3440
      _ExtentY        =   582
      ConnectMode     =   0
      CursorLocation  =   3
      IsolationLevel  =   -1
      ConnectionTimeout=   15
      CommandTimeout  =   30
      CursorType      =   3
      LockType        =   3
      CommandType     =   8
      CursorOptions   =   0
      CacheSize       =   50
      MaxRecords      =   0
      BOFAction       =   0
      EOFAction       =   0
      ConnectStringType=   1
      Appearance      =   1
      BackColor       =   -2147483643
      ForeColor       =   -2147483640
      Orientation     =   0
      Enabled         =   -1
      Connect         =   ""
      OLEDBString     =   ""
      OLEDBFile       =   ""
      DataSourceName  =   ""
      OtherAttributes =   ""
      UserName        =   ""
      Password        =   ""
      RecordSource    =   ""
      Caption         =   "1.ITC"
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      _Version        =   393216
   End
   Begin VB.Frame Frame2 
      BackColor       =   &H00E0E0E0&
      BorderStyle     =   0  'None
      Caption         =   "Frame2"
      Height          =   4005
      Left            =   90
      TabIndex        =   3
      Top             =   2295
      Width           =   10845
      Begin MSDataGridLib.DataGrid grdICT 
         Bindings        =   "frmINV540.frx":0000
         Height          =   4005
         Left            =   15
         TabIndex        =   4
         Top             =   15
         Width           =   10890
         _ExtentX        =   19209
         _ExtentY        =   7064
         _Version        =   393216
         BackColor       =   -2147483624
         ForeColor       =   12582912
         HeadLines       =   1
         RowHeight       =   15
         FormatLocked    =   -1  'True
         BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ColumnCount     =   12
         BeginProperty Column00 
            DataField       =   ""
            Caption         =   ""
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1036
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column01 
            DataField       =   "TCITN"
            Caption         =   "Item code"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1036
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column02 
            DataField       =   "IMITD"
            Caption         =   "Item Desc"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1036
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column03 
            DataField       =   "WMDSC"
            Caption         =   "Warehouse"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1036
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column04 
            DataField       =   "TCLOT"
            Caption         =   "LOT"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1036
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column05 
            DataField       =   "TCOHQ"
            Caption         =   "Onhand Unt"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "0"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1036
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column06 
            DataField       =   "TCOHW"
            Caption         =   "Onhand Wgt"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "0"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1036
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column07 
            DataField       =   "TCPCQ"
            Caption         =   "Physical Unt"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "0"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1036
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column08 
            DataField       =   "TCPCW"
            Caption         =   "Physical Wgt"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "0"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1036
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column09 
            DataField       =   "TCDTC"
            Caption         =   "Count Date"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1036
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column10 
            DataField       =   "TCVAL"
            Caption         =   "Value"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "0"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1036
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column11 
            DataField       =   "TCREM"
            Caption         =   "Remark"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1036
               SubFormatType   =   0
            EndProperty
         EndProperty
         SplitCount      =   2
         BeginProperty Split0 
            Size            =   378
            BeginProperty Column00 
               ColumnWidth     =   14.74
            EndProperty
            BeginProperty Column01 
               ColumnWidth     =   1140.095
            EndProperty
            BeginProperty Column02 
               ColumnWidth     =   1635.024
            EndProperty
            BeginProperty Column03 
            EndProperty
            BeginProperty Column04 
               ColumnWidth     =   1184.882
            EndProperty
            BeginProperty Column05 
            EndProperty
            BeginProperty Column06 
            EndProperty
            BeginProperty Column07 
            EndProperty
            BeginProperty Column08 
            EndProperty
            BeginProperty Column09 
            EndProperty
            BeginProperty Column10 
            EndProperty
            BeginProperty Column11 
            EndProperty
         EndProperty
         BeginProperty Split1 
            Size            =   326
            BeginProperty Column00 
               ColumnWidth     =   14.74
            EndProperty
            BeginProperty Column01 
               ColumnWidth     =   1335.118
            EndProperty
            BeginProperty Column02 
            EndProperty
            BeginProperty Column03 
            EndProperty
            BeginProperty Column04 
            EndProperty
            BeginProperty Column05 
            EndProperty
            BeginProperty Column06 
            EndProperty
            BeginProperty Column07 
            EndProperty
            BeginProperty Column08 
            EndProperty
            BeginProperty Column09 
            EndProperty
            BeginProperty Column10 
            EndProperty
            BeginProperty Column11 
            EndProperty
         EndProperty
      End
   End
   Begin VB.Frame FrameCountTag 
      BackColor       =   &H00E0E0E0&
      BorderStyle     =   0  'None
      Caption         =   "Frame1"
      Height          =   1005
      Left            =   90
      TabIndex        =   2
      Top             =   1080
      Width           =   10815
      Begin VB.TextBox txtTCDTE 
         Alignment       =   1  'Right Justify
         BeginProperty Font 
            Name            =   "Verdana"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   288
         Left            =   5535
         TabIndex        =   18
         Top             =   75
         Width           =   2250
      End
      Begin VB.TextBox txtTCTNo 
         Alignment       =   1  'Right Justify
         BeginProperty Font 
            Name            =   "Verdana"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   300
         Left            =   1335
         TabIndex        =   17
         Top             =   90
         Width           =   1425
      End
      Begin MSDataListLib.DataCombo cboTCITN3 
         Bindings        =   "frmINV540.frx":0015
         Height          =   315
         Left            =   6750
         TabIndex        =   16
         Top             =   465
         Width           =   3975
         _ExtentX        =   7011
         _ExtentY        =   556
         _Version        =   393216
         ListField       =   "IMITD"
         BoundColumn     =   "IMITN"
         Text            =   ""
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Verdana"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
      End
      Begin MSDataListLib.DataCombo cboTCITN2 
         Bindings        =   "frmINV540.frx":002A
         Height          =   315
         Left            =   1335
         TabIndex        =   15
         Top             =   480
         Width           =   3945
         _ExtentX        =   6959
         _ExtentY        =   556
         _Version        =   393216
         ListField       =   "IMITD"
         BoundColumn     =   "IMITN"
         Text            =   ""
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Verdana"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
      End
      Begin VB.TextBox txtTCITN3 
         Alignment       =   1  'Right Justify
         BeginProperty Font 
            Name            =   "Verdana"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   288
         Left            =   6735
         TabIndex        =   14
         Top             =   465
         Width           =   1425
      End
      Begin VB.TextBox txtIMITD3 
         BeginProperty Font 
            Name            =   "Verdana"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   288
         Left            =   8160
         Locked          =   -1  'True
         TabIndex        =   13
         Top             =   465
         Width           =   2550
      End
      Begin VB.TextBox txtTCITN2 
         Alignment       =   1  'Right Justify
         BeginProperty Font 
            Name            =   "Verdana"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   288
         Left            =   1365
         TabIndex        =   12
         Top             =   495
         Width           =   1425
      End
      Begin VB.TextBox txtIMITD2 
         BeginProperty Font 
            Name            =   "Verdana"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   288
         Left            =   2760
         Locked          =   -1  'True
         TabIndex        =   11
         Top             =   495
         Width           =   2550
      End
      Begin VB.CheckBox chkTCALL 
         Caption         =   "Check1"
         Height          =   240
         Left            =   8775
         TabIndex        =   10
         Top             =   60
         Width           =   225
      End
      Begin VB.Label lbl 
         BackStyle       =   0  'Transparent
         Caption         =   "All Item"
         BeginProperty Font 
            Name            =   "Verdana"
            Size            =   7.5
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H000000C0&
         Height          =   255
         Index           =   6
         Left            =   9195
         TabIndex        =   9
         Top             =   90
         Width           =   885
      End
      Begin VB.Label lbl 
         BackStyle       =   0  'Transparent
         Caption         =   "Item to"
         BeginProperty Font 
            Name            =   "Verdana"
            Size            =   7.5
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00800000&
         Height          =   255
         Index           =   5
         Left            =   5805
         TabIndex        =   8
         Top             =   480
         Width           =   750
      End
      Begin VB.Label lbl 
         BackStyle       =   0  'Transparent
         Caption         =   "Item from"
         BeginProperty Font 
            Name            =   "Verdana"
            Size            =   7.5
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00800000&
         Height          =   255
         Index           =   4
         Left            =   210
         TabIndex        =   7
         Top             =   540
         Width           =   990
      End
      Begin VB.Label lbl 
         BackStyle       =   0  'Transparent
         Caption         =   "Tag Date"
         BeginProperty Font 
            Name            =   "Verdana"
            Size            =   7.5
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00800000&
         Height          =   255
         Index           =   3
         Left            =   4485
         TabIndex        =   6
         Top             =   150
         Width           =   870
      End
      Begin VB.Label lbl 
         BackStyle       =   0  'Transparent
         Caption         =   "Tag No"
         BeginProperty Font 
            Name            =   "Verdana"
            Size            =   7.5
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00800000&
         Height          =   255
         Index           =   2
         Left            =   480
         TabIndex        =   5
         Top             =   135
         Width           =   675
      End
   End
   Begin VB.Label lbl 
      BackStyle       =   0  'Transparent
      Caption         =   "INV540"
      BeginProperty Font 
         Name            =   "VNI-Present"
         Size            =   18
         Charset         =   0
         Weight          =   700
         Underline       =   -1  'True
         Italic          =   -1  'True
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00E0E0E0&
      Height          =   510
      Index           =   0
      Left            =   60
      TabIndex        =   1
      Top             =   30
      Width           =   1755
   End
   Begin VB.Label lbl 
      BackStyle       =   0  'Transparent
      Caption         =   "Physical Count Tag Entry"
      BeginProperty Font 
         Name            =   "Verdana"
         Size            =   16.5
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   -1  'True
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00E0E0E0&
      Height          =   540
      Index           =   1
      Left            =   2295
      TabIndex        =   0
      Top             =   255
      Width           =   5820
   End
End
Attribute VB_Name = "frmINV540"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

Private Sub cboTCITN2_Click(Area As Integer)
If Area = 2 Then
    txtTCITN2 = cboTCITN2.BoundText
    txtIMITD2 = cboTCITN2.Text
    cboTCITN2.Visible = False
End If

End Sub
Sub CreateICT(TagNo, TCITN2, TCITN3, TCALL)
Dim RecIIM, RecIWI, RecILI As Recordset, IMITD, WMDSC
If TCALL Then
    Set RecIIM = DBconn.Execute("Select * FROM IIM ORDER BY IMTYP,IMCLC,IMITN")
Else
    Set RecIIM = DBconn.Execute("Select * from IIM WHERE IMITN>='" & TCITN2 & "' AND IMITN<='" & TCITN3 & "' ORDER BY IMTYP,IMCLC,IMITN")
End If
TCTNO = TagNo

TCDTE = Format(Now(), "yyyy-mm-dd hh:mm:ss")
Do While Not RecIIM.EOF
    TCITN = RecIIM!imitn
    TCWHC = ""
    TCLOT = ""
    TCOHW = RecIIM!IMOBW + RecIIM!IMRCW + RecIIM!IMAJW - RecIIM!IMISW
    TCOHQ = RecIIM!IMOBU + RecIIM!IMRCU + RecIIM!IMAJU - RecIIM!IMISU
    IMITD = RecIIM!IMITD
    If RecIIM!IMPER = "Unt" Then
        TCVAL = TCOHQ * RecIIM!IMATC
    Else
        TCVAL = TCOHW * RecIIM!IMATC
    End If
    SQL = "INSERT INTO ICTTEMP(TCTNO,TCITN2,TCITN3,TCITN,TCWHC,TCLOT" & _
    ",TCOHW,TCOHQ,TCPCW,TCPCQ,TCDTE,TCVAL,TCALL,SOMAY,IMITD) VALUES " & _
    "('" & TCTNO & "','" & TCITN2 & "','" & TCITN3 & "','" & TCITN & "','" & TCWHC & "','" & TCLOT & "'" & _
    "," & TCOHW & "," & TCOHQ & ",0,0,'" & TCDTE & "'," & TCVAL & "," & TCALL & "," & MAYSO & ",'" & IMITD & "')"
    
    DBconn.Execute SQL
    
    Set RecIWI = DBconn.Execute("SELECT * FROM IWI WHERE IWITN='" & TCITN & "' ORDER BY IWWHC")
    Do While Not RecIWI.EOF
        TCWHC = RecIWI!IWWHC
        TCOHW = RecIWI!IWOBW + RecIWI!IWRCW + RecIWI!IWAJW - RecIWI!IWISW
        TCOHQ = RecIWI!IWOBU + RecIWI!IWRCU + RecIWI!IWAJU - RecIWI!IWISU
        WMDSC = Find("IWM", "WMDSC", " WHERE WMWHC='" & TCWHC & "'")
        If RecIIM!IMPER = "Unt" Then
            TCVAL = TCOHQ * RecIIM!IMATC
        Else
            TCVAL = TCOHW * RecIIM!IMATC
        End If
        SQL = "INSERT INTO ICTTEMP(TCTNO,TCITN2,TCITN3,TCITN,TCWHC,TCLOT" & _
        ",TCOHW,TCOHQ,TCPCW,TCPCQ,TCDTE,TCVAL,TCALL,SOMAY,WMDSC) VALUES " & _
        "('" & TCTNO & "','" & TCITN2 & "','" & TCITN3 & "','" & TCITN & "','" & TCWHC & "','" & TCLOT & "'" & _
        "," & TCOHW & "," & TCOHQ & ",0,0,'" & TCDTE & "'," & TCVAL & "," & TCALL & "," & MAYSO & ",'" & WMDSC & "')"
        
        DBconn.Execute SQL
        
        Set RecILI = DBconn.Execute("SELECT * FROM ILI WHERE ILITN='" & TCITN & "' AND ILWHC='" & TCWHC & "' ORDER BY ILWHC")
        Do While Not RecILI.EOF
            TCLOT = RecILI!ILLOT
            TCOHW = RecILI!ILOBW + RecILI!ILRCW + RecILI!ILAJW - RecILI!ILISW
            TCOHQ = RecILI!ILOBU + RecILI!ILRCU + RecILI!ILAJU - RecILI!ILISU
            If RecIIM!IMPER = "Unt" Then
                TCVAL = TCOHQ * RecIIM!IMATC
            Else
                TCVAL = TCOHW * RecIIM!IMATC
            End If
            SQL = "INSERT INTO ICTTEMP(TCTNO,TCITN2,TCITN3,TCITN,TCWHC,TCLOT" & _
            ",TCOHW,TCOHQ,TCPCW,TCPCQ,TCDTE,TCVAL,TCALL,SOMAY,IMITD,WMDSC) VALUES " & _
            "('" & TCTNO & "','" & TCITN2 & "','" & TCITN3 & "','" & TCITN & "','" & TCWHC & "','" & TCLOT & "'" & _
            "," & TCOHW & "," & TCOHQ & ",0,0,'" & TCDTE & "'," & TCVAL & "," & TCALL & "," & MAYSO & ",'" & IMITD & "','" & WMDSC & "')"
           
            DBconn.Execute SQL
            
            RecILI.MoveNext
        Loop
        TCLOT = ""
        RecIWI.MoveNext
    Loop
    TCWHC = ""
    RecIIM.MoveNext
Loop
Adodc1.RecordSource = "SELECT ICTTEMP.TCITN, IIM.IMITD, IWM.WMdsc,ICTTEMP.TCWHC, ICTTEMP.TCLOT, " & _
    "ICTTEMP.TCOHQ, ICTTEMP.TCOHW, ICTTEMP.TCPCQ, ICTTEMP.TCPCW, ICTTEMP.TCDTC," & _
    "ICTTEMP.TCVAL, ICTTEMP.TCREM FROM ICTTEMP INNER JOIN " & _
    " IIM ON ICTTEMP.TCITN = IIM.IMITN LEFT OUTER JOIN " & _
    " IWM ON ICTTEMP.TCWHC = IWM.WMWHC WHERE ICTTEMP.SOMAY= " & MAYSO & "  order by TCIDN "
Adodc1.Refresh
End Sub
Sub tam()

End Sub

Private Sub cboTCITN3_Click(Area As Integer)
If Area = 2 Then
    txtTCITN3 = cboTCITN3.BoundText
    txtIMITD3 = cboTCITN3.Text
    If ISADDING Then CreateICT txtTCTNo, txtTCITN2, txtTCITN3, chkTCALL
    cboTCITN3.Visible = False
End If
End Sub

Private Sub chkTCALL_Click()
If chkTCALL.value = 1 Then
    CreateICT txtTCTNo, txtTCITN2, txtTCITN3, chkTCALL
End If
End Sub

Private Sub cmdAddNew_Click()
ISADDING = True
ISEDITING = True
txtTCTNo = "PC" & Right(str(Year(Date)), 2) & InsertPreCharacter("0", Month(Date), 2) & InsertPreCharacter("0", Day(Date), 2)
Dim RECICT As Recordset
Set RECICT = DBconn.Execute("SELECT * FROM ICT WHERE TCTNO='" & TXTTCNO & "'")
If Not RECICT.EOF Then
    Response = MsgBox("This count tag is already exist. Do you want to overwrite it?", vbYesNo + vbCritical + vbDefaultButton2, "Chu y'")
    If Response = vbNo Then
        Exit Sub
    End If
End If
ReadToScreen
ButtonStatus
End Sub

Private Sub cmdCancel_Click()
ISADDING = False
ISEDITING = False
ButtonStatus
End Sub

Private Sub cmdExit_Click()
Unload frmINV540
End Sub

Private Sub cmdReview_Click()
frmReview.Tag = "INV540"
frmReview.Show 1
txtTCTNo = frmReview.GridList.Columns(1)
ReadToScreen
End Sub

Private Sub cmdSave_Click()
WriteToICT
ISADDING = False
ISEDITING = False

ButtonStatus
End Sub

Sub OpenFile()
Adodc1.ConnectionString = ConnectString
Adodc1.ConnectionTimeout = 10
Adodc1.CommandType = adCmdText
Adodc1.RecordSource = "SELECT ICTTEMP.TCITN, IIM.IMITD, IWM.WMdsc,ICTTEMP.TCWHC, ICTTEMP.TCLOT, " & _
    "ICTTEMP.TCOHQ, ICTTEMP.TCOHW, ICTTEMP.TCPCQ, ICTTEMP.TCPCW, ICTTEMP.TCDTC," & _
    "ICTTEMP.TCVAL, ICTTEMP.TCREM FROM ICTTEMP INNER JOIN " & _
    " IIM ON ICTTEMP.TCITN = IIM.IMITN LEFT OUTER JOIN " & _
    " IWM ON ICTTEMP.TCWHC = IWM.WMWHC WHERE ICTTEMP.SOMAY= " & MAYSO & "  order by TCIDN "
Adodc1.Refresh

Adodc2.ConnectionString = ConnectString
Adodc2.ConnectionTimeout = 10
Adodc2.CommandType = adCmdText
FieldDel = "IMRID"
DelStatus = "IZ"
Adodc2.RecordSource = "select IMITN, IMITN + ' ' + IMITD as IMITD from IIM where " & FieldDel & " <>'" & DelStatus & "'"
Adodc2.Refresh
End Sub
Sub ReadToScreen()
DBconn.Execute ("Delete  from ICTTEMP where SOMAY=" & MAYSO)
If ISADDING Then
    txtTCDTE = Now()
    txtTCITN2 = ""
    txtIMITD2 = ""
    txtTCITN3 = ""
    txtIMITD3 = ""
    cboTCITN2.Visible = False
    cboTCITN3.Visible = False
    chkTCALL.value = 0
Else
    SQL = "INSERT INTO ICTTEMP (TCTNO,TCITN,TCITN2,TCITN3, TCWHC, TCLOT " & _
    ",TCOHQ, TCOHW, TCPCQ, TCPCW, TCDTC,TCDTE,TCALL" & _
    ",TCVAL , TCREM,SOMAY,IMITD, WMDSC)" & _
    " select ICT.TCTNO,ICT.TCITN,ICT.TCITN2,ICT.TCITN3,ICT.TCWHC,ICT.TCLOT " & _
    ",ICT.TCOHQ, ICT.TCOHW, ICT.TCPCQ, ICT.TCPCW, ICT.TCDTC,ICT.TCDTE,ICT.TCALL" & _
    ",TCVAL , TCREM," & MAYSO & ",IIM.IMITD,IWM.WMDSC FROM ICT INNER JOIN " & _
    " IIM ON ICT.TCITN = IIM.IMITN LEFT OUTER JOIN " & _
    " IWM ON ICT.TCWHC = IWM.WMWHC " & _
    " WHERE TCTNO='" & txtTCTNo & "'"
    DBconn.Execute SQL
    Dim RECICT As Recordset
    Set RECICT = DBconn.Execute("Select * from ICTTEMP where SOMAY=" & MAYSO)
    With RECICT
        txtTCDTE = !TCDTE
        txtTCITN2 = !TCITN2
        txtIMITD2 = Find("IIM", "IMITD", "WHERE IMITN='" & txtTCITN2 & "'")
        txtTCITN3 = !TCITN3
        txtIMITD3 = Find("IIM", "IMITD", "WHERE IMITN='" & txtTCITN3 & "'")
        cboTCITN2.Visible = False
        cboTCITN3.Visible = False
        chkTCALL.value = !TCALL
    End With
End If
'Adodc1.RecordSource = "SELECT ICTTEMP.TCITN, IIM.IMITD, IWM.WMdsc,ICTTEMP.TCWHC, ICTTEMP.TCLOT, " & _
    "ICTTEMP.TCOHQ, ICTTEMP.TCOHW, ICTTEMP.TCPCQ, ICTTEMP.TCPCW, ICTTEMP.TCDTC," & _
    "ICTTEMP.TCVAL, ICTTEMP.TCREM FROM ICTTEMP INNER JOIN " & _
    " IIM ON ICTTEMP.TCITN = IIM.IMITN LEFT OUTER JOIN " & _
    " IWM ON ICTTEMP.TCWHC = IWM.WMWHC WHERE ICTTEMP.SOMAY= " & MAYSO & "  order by TCIDN "
Adodc1.RecordSource = "SELECT ICTTEMP.TCITN, ICTTEMP.IMITD, ICTTEMP.WMdsc,ICTTEMP.TCWHC, ICTTEMP.TCLOT, " & _
    "ICTTEMP.TCOHQ, ICTTEMP.TCOHW, ICTTEMP.TCPCQ, ICTTEMP.TCPCW, ICTTEMP.TCDTC," & _
    "ICTTEMP.TCVAL, ICTTEMP.TCREM FROM ICTTEMP  WHERE ICTTEMP.SOMAY= " & MAYSO & "  order by TCIDN "
Adodc1.Refresh

End Sub

Private Sub Form_Load()
OpenFile
End Sub

Private Sub txtTCITN2_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
    Dim Result As String
    Result = Find("IIM", "IMITD", "WHERE IMITN='" & txtTCITN2 & "'")
    If Result = "" Then
        cboTCITN2.Visible = True
        cboTCITN2.SetFocus
    Else
        txtIMITD2 = Result
    End If
    
End If
End Sub

Private Sub txtTCITN3_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
    Dim Result As String
    Result = Find("IIM", "IMITD", "WHERE IMITN='" & txtTCITN3 & "'")
    If Result = "" Then
        cboTCITN3.Visible = True
        cboTCITN3.SetFocus
    Else
        txtIMITD3 = Result
        If ISADDING Then CreateICT txtTCTNo, txtTCITN2, txtTCITN3, chkTCALL
    End If
    
End If
End Sub
Sub WriteToICT()
DBconn.Execute ("DELETE FROM ICT WHERE TCTNO='" & txtTCTNo & "'")
 SQL = "INSERT INTO ICT(TCTNO,TCITN,TCITN2,TCITN3,TCWHC, TCLOT " & _
    ",TCOHQ, TCOHW, TCPCQ, TCPCW, TCDTC,TCDTE,TCALL" & _
    ",TCVAL , TCREM,SOMAY)" & _
    " select TCTNO,TCITN,TCITN2,TCITN3,TCWHC, TCLOT " & _
    ",TCOHQ, TCOHW, TCPCQ, TCPCW, TCDTC,TCDTE,TCALL" & _
    ",TCVAL , TCREM," & MAYSO & " FROM ICTTEMP WHERE SOMAY=" & MAYSO & "ORDER BY TCIDN"
    DBconn.Execute SQL
End Sub

Sub ButtonStatus()
cmdAddNew.Enabled = Not ISEDITING
cmdReview.Enabled = Not ISEDITING

cmdSave.Enabled = ISEDITING
cmdCancel.Enabled = ISEDITING
FrameCountTag.Enabled = ISADDING
End Sub

